package com.sunda.spmsweb.wmscontroller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsweb.util.JWTUtil;
import com.sunda.spmswms.service.IShelfOnTaskDtlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 上架任务表明细 前端控制器
 * </p>
 *
 * @author Wayne
 * @since 2021-03-19
 */
@RestController
@RequestMapping("/shelfOntaskDtl")
@Api(tags = "上架下架任务明细", description = "上架下架任务明细接口")
public class ShelfOnTaskDtlController {

    @Autowired
    IShelfOnTaskDtlService iShelfOnTaskDtlService;



    @PostMapping("/completeShelfOnTaskDtl")
    @ApiOperation(value = "完成上架任务(备件货)",notes = "完成上架任务(备件货)\n" +
            "{\n" +
            "    \"shelfOnUuid\":\"shelfOnUuid\",\n" +
            "    \"shelfOnTaskDtl\":[{\n" +
            "        \"boxNote\":\"ZX-10215800023-0202\",\n" +
            "        \"targetStorage\":\"b95946ac1dab42b79ade3438acb0b53a\",\n" +
            "        \"boxQtyReceived\":1,\n" +
            "        \"deliveryNoteSap\": \"deliveryNoteSap\"\n" +
            "    }]\n" +
            "}\n")
    public ResponseResult completeShelfOnTaskDtl(@RequestBody JSONObject jsonObject){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            String shelfOnUuid=jsonObject.containsKey("shelfOnUuid")?jsonObject.getString("shelfOnUuid"):null;
            JSONArray shelfOnTaskDtl= jsonObject.containsKey("shelfOnTaskDtl")?jsonObject.getJSONArray("shelfOnTaskDtl"):null;
            if(null==shelfOnUuid || null==shelfOnTaskDtl){
                return ResponseResult.error("shelfOnUuid and shelfOnTaskDtl is mandatory required");
            }
             return iShelfOnTaskDtlService.completeShelfOnTaskDtlByBoxNote(shelfOnUuid,shelfOnTaskDtl,userId);

        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("Error when update Shelf On tasks");
        }
    }
}
